#include<iostream>
using namespace std;
#include<vector>
#include<string>

class Solution {
public:
    //经测试 本题只使用back
    void test() {
        vector<char> v;
        v.push_back('A');
        v.push_back('B');
        v.push_back('C');
        v.push_back('D');
        cout << "front:" << v.front() << endl
            << "back:" << v.back() << endl;
        // this->removeBottomElement(v);
        cout << "before reverse:" << endl;
        for(auto it=v.begin(); it!=v.end(); it++) {
            cout << *it << endl;
        }
        this->reverse(v);
        cout << "after reverse:" << endl;
        for(auto it=v.begin(); it!=v.end(); it++) {
            cout << *it << endl;
        }
    }
    //将栈底元素移除
    char removeBottomElement(vector<char>& v) {
        char ret;
        if(v.size() == 1) {
            ret = v.back();
            v.pop_back();
        } else if(v.size() >= 2){
            char cur = v.back();
            v.pop_back();
            ret = this->removeBottomElement(v);
            v.push_back(cur);
        }
        return ret;
    }
    //逆序栈
    void reverse(vector<char>& v) {
        if(v.size() > 1) {
            char ret = this->removeBottomElement(v);
            this->reverse(v);
            v.push_back(ret);
        }
    }
};

int main() {
    Solution().test();
    return 0;
}